package com.yygo.dao.hibernate;

import com.yygo.Constants;
import com.yygo.dao.MoneyTransferDao;
import com.yygo.model.MoneyTransferRecord;
import com.yygo.model.User;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by tiansha on 2015/11/7.
 */
@Repository("moneyTransferDao")
public class MoneyTransferDaoHibernate extends GenericDaoHibernate<MoneyTransferRecord, Long> implements MoneyTransferDao {

    public MoneyTransferDaoHibernate() {
        super(MoneyTransferRecord.class);
    }

    @Override
    public List<MoneyTransferRecord> getPendingMoneyTransferRecords(User user) {
        Criteria criteria = getSession().createCriteria(MoneyTransferRecord.class).add(Restrictions.eq("status", Constants.STATUS_PENDING));
        criteria.createCriteria("loanRequest").createCriteria("loanProduct").createCriteria("bank").add(Restrictions.eq("bankUser", user));
        List moneyTransferRecords = criteria.list();
        return moneyTransferRecords;
    }

    @Override
    public List<MoneyTransferRecord> getTransferredMoneyTransferRecords(User user) {
        Criteria criteria = getSession().createCriteria(MoneyTransferRecord.class).add(Restrictions.eq("status", Constants.STATUS_TRANSFERRED));
        criteria.createCriteria("loanRequest").createCriteria("loanProduct").createCriteria("bank").add(Restrictions.eq("bankUser", user));
        List moneyTransferRecords = criteria.list();
        return moneyTransferRecords;
    }
}
